package com.example.demo.controller;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.custom.AjaxResult;
import com.example.demo.custom.BaseController;
import com.example.demo.entity.AftersalesWarehouse;
import com.example.demo.form.AftersalesWarehouseFrom;
import com.example.demo.service.AftersalesWarehouseService;
@RestController
@RequestMapping(value = "/AftersalesWarehouse")
public class AftersalesWarehouseController extends BaseController<AftersalesWarehouse, Integer, AftersalesWarehouseFrom>{
	@Autowired	
	private AftersalesWarehouseService aftersalesWarehouseDAO;
	
	@RequestMapping(value="/save1")
	public Object save1(AftersalesWarehouseFrom Form) throws ParseException {
		DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
		Integer saleId1 = Form.getId();
		Date d= new Date();
		Date d1 = dateFormat1.parse("1999-01-01");
		AftersalesWarehouse After=new AftersalesWarehouse();
		AftersalesWarehouse after=new AftersalesWarehouse();
		BeanUtils.copyProperties(Form, After, "id");
		After.setBeginDate(d);
		aftersalesWarehouseDAO.save(After);
		
		
		return new AjaxResult(false,"数据保存失败");
	}
	@RequestMapping(value="/findbyId")
	public Object byId(AftersalesWarehouseFrom form) {
		AftersalesWarehouse model = null;
		Integer id = form.getId();
		if(id!=null) {
			 model = aftersalesWarehouseDAO.findById(id);
		}	
		return new AjaxResult(model);
	}
	//配件基础信息
	public Object parts() {
		List<AftersalesWarehouse> listy=aftersalesWarehouseDAO.findAll();
		AftersalesWarehouse after=listy.stream().filter(u -> u.getComeparts().equals("养护品")).findAny().orElse(null);
		System.out.println("养护品"+after);
		return null;
	}
}
